home *** CD-ROM | disk | FTP | other *** search
- package sunw.demo.molecule;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Panel;
- import java.awt.event.ActionEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
-
- public class Molecule extends Panel implements Serializable, MouseListener, MouseMotionListener {
- private static int ourVersion = 3;
- // $FF: renamed from: md sunw.demo.molecule.XYZChemModel
- XYZChemModel field_0;
- float xfac;
- int prevx;
- int prevy;
- float xtheta;
- float ytheta;
- float scalefudge;
- Matrix3D amat;
- Matrix3D tmat;
- String message;
- Image backBuffer;
- Graphics backGC;
- private String moleculeName = "HyaluronicAcid";
-
- public Molecule() {
- this.reset();
- this.amat.yrot((double)20.0F);
- this.amat.xrot((double)20.0F);
- ((Component)this).setBackground(Color.white);
- ((Component)this).addMouseListener(this);
- ((Component)this).addMouseMotionListener(this);
- }
-
- public Dimension getPreferredSize() {
- return new Dimension(150, 150);
- }
-
- /** @deprecated */
- public Dimension preferredSize() {
- return this.getPreferredSize();
- }
-
- public synchronized void initialize() {
- InputStream var1 = null;
-
- try {
- var1 = this.getClass().getResourceAsStream(this.moleculeName + ".xyz");
- XYZChemModel var2 = new XYZChemModel(var1);
- Atom.setPanel(this);
- this.field_0 = var2;
- var2.findBB();
- float var3 = var2.xmax - var2.xmin;
- float var4 = var2.ymax - var2.ymin;
- float var5 = var2.zmax - var2.zmin;
- if (var4 > var3) {
- var3 = var4;
- }
-
- if (var5 > var3) {
- var3 = var5;
- }
-
- float var6 = (float)((Component)this).getSize().width / var3;
- float var7 = (float)((Component)this).getSize().height / var3;
- this.xfac = 0.7F * (var6 < var7 ? var6 : var7) * this.scalefudge;
- this.backBuffer = ((Component)this).createImage(((Component)this).getSize().width, ((Component)this).getSize().height);
- this.backGC = this.backBuffer.getGraphics();
- } catch (Exception var9) {
- ((Throwable)var9).printStackTrace();
- this.field_0 = null;
- this.message = ((Throwable)var9).toString();
- }
-
- try {
- if (var1 != null) {
- var1.close();
- return;
- }
- } catch (Exception var8) {
- }
-
- }
-
- private synchronized void rotate(int var1, int var2) {
- this.tmat.unit();
- float var3 = (float)(this.prevy - var2) * (360.0F / (float)((Component)this).getSize().width);
- float var4 = (float)(var1 - this.prevx) * (360.0F / (float)((Component)this).getSize().height);
- this.tmat.xrot((double)var3);
- this.tmat.yrot((double)var4);
- this.amat.mult(this.tmat);
- ((Component)this).repaint();
- this.prevx = var1;
- this.prevy = var2;
- }
-
- public void mouseClicked(MouseEvent var1) {
- }
-
- public synchronized void mousePressed(MouseEvent var1) {
- this.prevx = var1.getX();
- this.prevy = var1.getY();
- }
-
- public void mouseReleased(MouseEvent var1) {
- }
-
- public void mouseEntered(MouseEvent var1) {
- }
-
- public void mouseExited(MouseEvent var1) {
- }
-
- public void mouseDragged(MouseEvent var1) {
- this.rotate(var1.getX(), var1.getY());
- }
-
- public void mouseMoved(MouseEvent var1) {
- }
-
- public synchronized void rotateOnY() {
- ((Component)this).getSize();
- int var1 = ((Component)this).getSize().height;
- int var2 = this.prevx;
- int var3 = (this.prevy + 10) % var1;
- this.rotate(var2, var3);
- }
-
- public synchronized void rotateY(ActionEvent var1) {
- this.rotateOnY();
- }
-
- public synchronized void rotateOnX() {
- int var1 = ((Component)this).getSize().width;
- ((Component)this).getSize();
- int var2 = (this.prevx + 10) % var1;
- int var3 = this.prevy;
- this.rotate(var2, var3);
- }
-
- public synchronized void rotateX(ActionEvent var1) {
- this.rotateOnX();
- }
-
- public synchronized void update(Graphics var1) {
- if (this.backBuffer == null) {
- var1.clearRect(0, 0, ((Component)this).getSize().width, ((Component)this).getSize().height);
- }
-
- this.paint(var1);
- }
-
- public synchronized void paint(Graphics var1) {
- if (this.backBuffer == null) {
- this.initialize();
- }
-
- if (this.field_0 != null) {
- this.field_0.mat.unit();
- this.field_0.mat.translate(-(this.field_0.xmin + this.field_0.xmax) / 2.0F, -(this.field_0.ymin + this.field_0.ymax) / 2.0F, -(this.field_0.zmin + this.field_0.zmax) / 2.0F);
- this.field_0.mat.mult(this.amat);
- this.field_0.mat.scale(this.xfac, -this.xfac, 16.0F * this.xfac / (float)((Component)this).getSize().width);
- this.field_0.mat.translate((float)(((Component)this).getSize().width / 2), (float)(((Component)this).getSize().height / 2), 8.0F);
- this.field_0.transformed = false;
- this.backGC.setColor(((Component)this).getBackground());
- this.backGC.fillRect(0, 0, ((Component)this).getSize().width, ((Component)this).getSize().height);
- this.field_0.paint(this.backGC);
- var1.drawImage(this.backBuffer, 0, 0, this);
- } else {
- if (this.message != null) {
- var1.drawString("Error in model:", 3, 20);
- var1.drawString(this.message, 10, 40);
- }
-
- }
- }
-
- private void writeObject(ObjectOutputStream var1) throws IOException {
- var1.writeInt(ourVersion);
- var1.writeObject(this.moleculeName);
- }
-
- private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
- this.reset();
- if (var1.readInt() != ourVersion) {
- throw new IOException("Molecule.readObject: version mismatch");
- } else {
- this.moleculeName = (String)var1.readObject();
- }
- }
-
- private synchronized void reset() {
- this.field_0 = null;
- this.xfac = 0.0F;
- this.prevx = 0;
- this.prevy = 0;
- this.xtheta = 0.0F;
- this.ytheta = 0.0F;
- this.scalefudge = 1.0F;
- this.amat = new Matrix3D();
- this.tmat = new Matrix3D();
- this.message = null;
- this.backBuffer = null;
- this.backGC = null;
- }
-
- public String getMoleculeName() {
- return this.moleculeName;
- }
-
- public void setMoleculeName(String var1) {
- this.moleculeName = var1;
- this.reset();
- ((Component)this).repaint();
- }
- }
-